from django.db import models
from django.contrib.auth import get_user_model
from ckeditor_uploader.fields import RichTextUploadingField
# 获取经过扩展字段后的Django的用户模型类
User = get_user_model()

# 笔记类型模型.

class Type(models.Model):
    name = models.CharField(max_length=100,verbose_name='类型名称')
    type_dec = models.CharField(max_length=254,verbose_name='类型描述',null=True,default='')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '笔记类型'
        verbose_name_plural = verbose_name


# 笔记的模型
class Note(models.Model):
    type = models.ForeignKey(Type,on_delete=models.SET_DEFAULT,default='无类型',verbose_name='笔记类型')
    user = models.ForeignKey(User,on_delete=models.SET_DEFAULT,default='作者不详',verbose_name='作者')
    title = models.CharField(max_length=200,verbose_name='笔记标题')
    content = RichTextUploadingField(verbose_name='笔记内容')
    read_num = models.IntegerField(verbose_name='阅读量',default=0)
    like_num = models.IntegerField(verbose_name='点赞数',default=0)
    pub_date = models.DateTimeField(verbose_name='发布时间',auto_now_add=True)
    is_delete = models.BooleanField(verbose_name='是否删除',default=False)

    class Meta:
        verbose_name = '笔记'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title